﻿Imports System.IO
Public Class Debugger
    Inherits System.Windows.Forms.Form
    Implements IMessageFilter
#Region "Dimensions and Variables"
    'Key down integers not entirely necessary, they just make things easier to read for me
    Private WM_KEYDOWN As Integer = &H100
    Private WM_KEYUP As Integer = &H101
    Private AddingDIGIT As Boolean, AddingBracket As Boolean
    Private SyntaxStarted As Boolean = False
    'Set Defaults
    Public DefaultColor As String = "/W"
    'Directory locations for important database locations
    Public DirMisc, DirMobs, DirItems, DirMaps, DirAtlasNodes, DirEmotes, DirScripts, DirAbilities, DirQuests, DirHelpFiles As String
    'The following are states for the databases when loaded and whether or not they're healthy
    Public MobileHealth, MapHealth, AtlasNodesHealth, ItemHealth, EmoteHealth, ScriptHealth, AbilitiesHealth As String
    Public MobileChanged, MapChanged, AtlasNodesChanged, ItemChanged, EmoteChanged, ScriptChanged, AbilitiesChanged, MiscChanged As Boolean
    'The following are save states
    Public EmotesSaved As Boolean = False, AtlasNodesSaved As Boolean = False
    Public ItemsSaved As Boolean = False, MobilesSaved As Boolean = False, ScriptsSaved As Boolean = False
    Public MiscSaved As Boolean = False, AbilitiesSaved As Boolean = False
    'indicates the currently open database, whether misc or not.
    Public Current = "None"
    'used for loading and saving of files, error types etc.
    Public serr As String
    Public bans As Boolean
    'the following data is where all the main databases are saved to.
    Public MiscData As String
    Public MapData As String
    Public AtlasNodesData As String
    Public EmoteData As String
    Public MobData As String
    Public ItemData As String
    Public ScriptData As String
    Public AbilitiesData As String
    'Errata dimensions
    Dim openhelptg As Boolean
    Dim openversiontg As Boolean
    Dim StartDigit As Boolean
    Dim DebuggerOpen As Boolean
    Public FileStatusOpen As Boolean
    Public EditorOpen As Boolean
    Public Closing As Boolean
    Public ResourcesDir As String
    'Changes Made / Saved Notifications
    Public FileChanged As Boolean
#End Region
#Region "Functions"
    Public Function StripXML(Original As String) As String
        'Xml.XmlReader.
        Dim CurPos As Integer, Stripping As Short, newString As String, started As Boolean, nextChar As String = "", prevChar As String
        Original = Replace(Original, Chr(10), Chr(13))
        For CurPos = 1 To Len(Original) Step 1 'step through the original string and strip the xml and save to a new string, then return it
            prevChar = nextChar
            nextChar = Replace(Mid(Original, CurPos, 1), Chr(10), "") 'makes annotating the next character easier
            If nextChar = "<" Then 'start ignoring string flagadd 1 (ensures that it ignores all inner flags as well
                Stripping += 1
            ElseIf nextChar = ">" And Stripping > 0 Then 'end a flag
                Stripping -= 1
            ElseIf Stripping = 0 Then 'there are no currently active flags, save current text to string
                If prevChar = Chr(13) And nextChar = Chr(13) Then
                    nextChar = prevChar
                Else 'ensure that there is no excess of carriage returns when stripping the xml.
                    If started = False And Asc(nextChar) > 22 Then
                        started = True
                        newString += nextChar
                    ElseIf started = True Then
                        If Asc(nextChar) > 22 Then
                            newString += nextChar
                        Else
                            nextChar = prevChar
                        End If
                    End If
                End If
            End If
        Next
        Return newString
    End Function
    Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
        Dim keyCode As Keys = CType(CInt(m.WParam), Keys) And Keys.KeyCode
        If m.Msg = WM_KEYDOWN And keyCode = Keys.Escape Then
            Me.Close()
            Application.RemoveMessageFilter(Me) : Return True
        End If
        Return False
    End Function
    Public Function GetFileContents(ByVal FullPath As String, _
         Optional ByRef ErrInfo As String = "") As String

        Dim strContents As String
        Dim objReader As StreamReader
        Try
            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            objReader.Dispose()
            Return strContents
        Catch Ex As Exception
            ErrInfo = Ex.Message
            MsgBox(ErrInfo, MsgBoxStyle.Critical, "ERROR!")
            Return ""
        End Try
    End Function
    Public Function SaveTextToFile(ByVal strData As String, _
     ByVal FullPath As String, _
       Optional ByVal ErrInfo As String = "") As Boolean

        Dim bAns As Boolean = False
        Dim trynum As Short = 1
        Dim objReader As StreamWriter
        While bAns = False
            Try
                objReader = New StreamWriter(FullPath)
                objReader.Write(strData)
                objReader.Close()
                bAns = True
            Catch Ex As Exception
                ErrInfo = Ex.Message
                If trynum = 1000 Then
                    MsgBox(ErrInfo, MsgBoxStyle.Critical, "ERROR!")
                    bAns = True
                End If
            End Try
        End While
        Return bAns
    End Function
#End Region
#Region "Form Initialization"
    Private Sub ShowSplash(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
        SplashScreen.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
        SplashScreen.Show()
    End Sub
    Private Sub openversionchanges(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VersionChangesToolStripMenuItem1.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "None"
        Editor.PAD.Enabled = False
        If openversiontg = False And openhelptg = False Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "ClayVersion.xml"), serr)
            SNDFORCE(StripXML(helpfiles))
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - Clay Version Information"
        ElseIf openhelptg = False And openversiontg = True And Me.Text = "Debugger - Clay Version Information" Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False
            Editor.PAD.ReadOnly = False
            openversiontg = False
            Me.Text = "Debugger"
        ElseIf openhelptg = False And openversiontg = True Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "ClayVersion.xml"), serr)
            SNDFORCE(StripXML(helpfiles))
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - Clay Version Information"
        End If
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
        Editor.PAD.Enabled = True
    End Sub
    Private Sub openversion2changes(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLOSChangesToolStripMenuItem.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "None"
        Editor.PAD.Enabled = False
        If openversiontg = False And openhelptg = False Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "PLOSVersion.xml"), serr)
            SNDFORCE(helpfiles)
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - PLOS Version Information"
        ElseIf openhelptg = False And openversiontg = True And Me.Text = "Debugger - PLOS Version Information" Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False
            Editor.PAD.ReadOnly = False
            openversiontg = False
            Me.Text = "Debugger"
        ElseIf openhelptg = False And openversiontg = True Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "PLOSVersion.xml"), serr)
            SNDFORCE(helpfiles)
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - PLOS Version Information"
        End If
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
        Editor.PAD.Enabled = True
    End Sub
#End Region
#Region "Colored Text / SND"
    Public Sub SND(ByVal Txt As String)
        Txt = DefaultColor + " " + Txt + DefaultColor
        Dim Switches As Integer = -1
        Dim TempStr As String
        Dim TempStr2 As String
        Dim TempInt As Integer
        Dim TempInt2 As Integer = 0
        For TempInt = 1 To Len(Txt) Step 1
            TempStr = Mid(Txt, TempInt, 1)
            If TempStr = "/" Then
                If Mid(Txt, TempInt, 2) = "/B" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/b" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H66)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/C" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/c" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H6666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/M" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFF00FF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/m" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H660066)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H666600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/Y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFFFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/g" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H6600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/G" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/w" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H666666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/W" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HAAAAAA)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H333333)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/Z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFFFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/R" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&HFF0000)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/r" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        databasemonitor.filestatus.SelectedText = TempStr2
                    End If
                    databasemonitor.filestatus.SelectionColor = Color.FromArgb(&H660000)
                    TempInt2 = TempInt
                    Switches += 1
                End If
            End If
        Next
        databasemonitor.filestatus.SelectedText = Chr(13)
    End Sub
    Public Sub SNDBUG(ByVal Txt As String)
        Txt = DefaultColor + " " + Txt + DefaultColor
        Dim Switches As Integer = -1
        Dim TempStr As String
        Dim TempStr2 As String
        Dim TempInt As Integer
        Dim TempInt2 As Integer = 0
        For TempInt = 1 To Len(Txt) Step 1
            TempStr = Mid(Txt, TempInt, 1)
            If TempStr = "/" Then
                If Mid(Txt, TempInt, 2) = "/B" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/b" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H66)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/C" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/c" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H6666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/M" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFF00FF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/m" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H660066)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H666600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/Y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFFFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/g" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H6600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/G" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/w" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H666666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/W" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HAAAAAA)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H333333)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/Z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/R" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(Txt, TempInt, 2) = "/r" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        CMDPanel.PAD.SelectedText = TempStr2
                    End If
                    CMDPanel.PAD.SelectionColor = Color.FromArgb(&H660000)
                    TempInt2 = TempInt
                    Switches += 1
                End If
            End If
        Next
        CMDPanel.PAD.SelectedText = Chr(13)
    End Sub
    Public Sub SNDFORCE(ByVal txt As String)
        txt = DefaultColor + " " + txt + DefaultColor
        Dim Switches As Integer = -1
        Dim TempStr As String
        Dim TempStr2 As String
        Dim TempInt As Integer
        Dim TempInt2 As Integer = 0
        For TempInt = 1 To Len(txt) Step 1
            TempStr = Mid(txt, TempInt, 1)
            If TempStr = "/" Then
                If Mid(txt, TempInt, 2) = "/B" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/b" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H66)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/C" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/c" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/M" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF00FF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/m" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H660066)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H666600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/Y" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/g" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H6600)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/G" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF00)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/w" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H666666)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/W" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HAAAAAA)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H333333)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/Z" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/R" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                    TempInt2 = TempInt
                    Switches += 1
                ElseIf Mid(txt, TempInt, 2) = "/r" Then
                    If TempInt2 <> 0 Then
                        TempStr2 = Mid(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(txt, "/b", ""), "/B", ""), "/g", ""), "/G", ""), "/m", ""), "/M", ""), "/w", ""), "/W", ""), "/y", ""), "/Y", ""), "/z", ""), "/Z", ""), "/c", ""), "/C", ""), "/r", ""), "/R", ""), TempInt2 - Switches * 2, TempInt - TempInt2 - 2)
                        Editor.PAD.SelectedText = TempStr2
                    End If
                    Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
                    TempInt2 = TempInt
                    Switches += 1
                End If
            End If
        Next
        Editor.PAD.SelectedText = Chr(13)
    End Sub
    Public Sub FormatTextColor(ByVal Thestring As String)
        If SyntaxStarted = True Then
            Editor.PAD.Enabled = False
            Dim tmp0 As Integer, tmp1 As Integer
            Dim EndOfColor As Integer = 0, totallen As Integer = 0
            Dim first As Boolean = True, last As Integer = 0
            Dim tmpA As String
            Editor.PAD.Text = Thestring
            For tmp1 = 0 To Editor.PAD.Lines.Length - 1 Step 1
                tmpA = Editor.PAD.Lines(tmp1)
                totallen = 0
                last = 0
                EndOfColor = 0
                If Len(tmpA) > 1 Then
                    Editor.PAD.SelectionStart = Editor.PAD.GetFirstCharIndexFromLine(tmp1)
                    For tmp0 = 1 To Len(tmpA) Step 1
                        If Mid(tmpA, tmp0, 2) = "//" And first = True Then
                            Editor.PAD.SelectionLength = Editor.PAD.Lines(tmp1).Length
                            Editor.PAD.SelectionColor = Color.FromArgb(&HFF00)
                            Exit For
                        End If
                        If Mid(tmpA, tmp0, 1) = "#" And first = True Then
                            first = False
                            EndOfColor = tmp0 - 1
                            Editor.PAD.SelectionLength = EndOfColor
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
                            Editor.PAD.SelectionStart += EndOfColor
                            Editor.PAD.SelectionLength = 1
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&H333333)
                            Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                            last = Editor.PAD.SelectionStart
                        ElseIf Mid(tmpA, tmp0, 1) = "(" And first = False Then
                            Editor.PAD.SelectionLength = tmp0 - 1 - totallen
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                            Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionLength = 1
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                            Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                        ElseIf Mid(tmpA, tmp0, 1) = ")" And first = False Then
                            Editor.PAD.SelectionLength = tmp0 - 1 - totallen
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
                            Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionLength = 1
                            totallen += Editor.PAD.SelectionLength
                            Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                            first = True
                            Exit For
                        End If
                    Next
                End If
            Next
            Editor.PAD.SelectionStart = 0
            Editor.PAD.SelectionLength = 0
            Editor.PAD.Enabled = True
            Editor.PAD.Focus()
        Else
            Editor.PAD.Text = Thestring
            Editor.PAD.SelectionStart = 0
            Editor.PAD.SelectionLength = Len(Editor.PAD.Text)
            If DefaultColor = "/B" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFF)
            ElseIf DefaultColor = "/b" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H66)
            ElseIf DefaultColor = "/C" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFFFF)
            ElseIf DefaultColor = "/c" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
            ElseIf DefaultColor = "/M" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFF00FF)
            ElseIf DefaultColor = "/m" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H660066)
            ElseIf DefaultColor = "/y" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H666600)
            ElseIf DefaultColor = "/Y" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFFFF00)
            ElseIf DefaultColor = "/g" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H6600)
            ElseIf DefaultColor = "/G" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFF00)
            ElseIf DefaultColor = "/w" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H666666)
            ElseIf DefaultColor = "/W" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HAAAAAA)
            ElseIf DefaultColor = "/z" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H333333)
            ElseIf DefaultColor = "/Z" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
            ElseIf DefaultColor = "/R" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
            ElseIf DefaultColor = "/r" Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
            End If
            Editor.PAD.SelectionStart = 1
            Editor.PAD.SelectionLength = 0
        End If
    End Sub
    Private Sub FormatLineColor()
        Dim tmp0 As Integer = Editor.PAD.SelectionStart, tmp1 As Integer = Editor.PAD.SelectionStart, Found As Boolean = False
        Dim TheLine As String, BeginSelection As Integer = 0, ResetPosition As Integer = Editor.PAD.SelectionStart
        If tmp0 > 1 Then
            For tmp0 = Editor.PAD.SelectionStart To 1 Step -1
                If Mid(Editor.PAD.Text, tmp0, 1) = Chr(10) Then
                    TheLine = Mid(Editor.PAD.Text, tmp0 + 1, tmp1 - tmp0)
                    Found = True
                    BeginSelection = tmp0
                    Exit For
                End If
            Next
        End If
        If Found = False Then TheLine = Mid(Editor.PAD.Text, 1, tmp1)
        If tmp1 > 1 Then
            For tmp1 = tmp1 + 1 To Len(Editor.PAD.Text) Step 1
                If Mid(Editor.PAD.Text, tmp1, 1) = Chr(10) Then
                    Exit For
                Else
                    TheLine += Mid(Editor.PAD.Text, tmp1, 1)
                End If
            Next
        End If
        Dim EndOfColor As Integer = 0, totallen As Integer = 0
        Dim first As Boolean = True, last As Integer = 0
        Dim tmpA As String = TheLine
        If Len(tmpA) > 1 Then
            Editor.PAD.SelectionStart = BeginSelection
            For tmp0 = 1 To Len(tmpA) Step 1
                If Mid(tmpA, tmp0, 2) = "//" And first = True Then
                    first = False
                    Editor.PAD.SelectionLength = Len(TheLine)
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF00)
                    Exit For
                End If
                If Mid(tmpA, tmp0, 1) = "#" And first = True Then
                    first = False
                    EndOfColor = tmp0 - 1
                    Editor.PAD.SelectionLength = EndOfColor
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
                    Editor.PAD.SelectionStart += EndOfColor
                    Editor.PAD.SelectionLength = 1
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&H333333)
                    Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                    last = Editor.PAD.SelectionStart
                ElseIf Mid(tmpA, tmp0, 1) = "(" And first = False Then
                    Editor.PAD.SelectionLength = tmp0 - 1 - totallen
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                    Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionLength = 1
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                    Editor.PAD.SelectionStart += Editor.PAD.SelectionLength
                ElseIf Mid(tmpA, tmp0, 1) = ")" And first = False Then
                    Editor.PAD.SelectionLength = tmp0 - 1 - totallen
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
                    Editor.PAD.SelectionStart += Editor.PAD.SelectionLength - 1
                    Editor.PAD.SelectionLength = 0
                    totallen += Editor.PAD.SelectionLength
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                    first = True
                    Exit For
                End If
            Next
            If first = True Then
                If tmp0 - 1 - totallen > 1 Then
                    Editor.PAD.SelectionLength = tmp0 - 1 - totallen
                End If
                Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
            End If
            Editor.PAD.SelectionStart = ResetPosition
            Editor.PAD.SelectionLength = 0
        End If
    End Sub
#End Region
#Region "Open Databases"
    Public Sub openheader(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenHeaderM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "AtlasNodes"
        If AtlasNodesData = "" Then
            AtlasNodesData = GetFileContents(DirAtlasNodes, serr)
        End If
        FormatTextColor(AtlasNodesData)
        SaveHeaderM.Enabled = True
        CloseHeaderM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openmobiles(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenMobileM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Mobiles"
        If MobData = "" Then
            MobData = GetFileContents(DirMobs, serr)
        End If
        FormatTextColor(MobData)
        SaveMobileM.Enabled = True
        CloseMobileM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openitems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenItemM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Items"
        If ItemData = "" Then
            ItemData = GetFileContents(DirItems, serr)
        End If
        FormatTextColor(ItemData)
        SaveItemM.Enabled = True
        CloseItemM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openemotes(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenEmoteM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Emotes"
        If EmoteData = "" Then
            EmoteData = GetFileContents(DirEmotes, serr)
        End If
        FormatTextColor(EmoteData)
        SaveEmoteM.Enabled = True
        CloseEmoteM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openabilities(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenAbilitiesM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Abilities"
        If AbilitiesData = "" Then
            AbilitiesData = GetFileContents(DirAbilities, serr)
        End If
        FormatTextColor(AbilitiesData)
        SaveAbilitiesM.Enabled = True
        CloseAbilitiesM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openscripts(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenScriptsM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Scripts"
        If ScriptData = "" Then
            ScriptData = GetFileContents(DirScripts, serr)
        End If
        FormatTextColor(ScriptData)
        SaveScriptsM.Enabled = True
        CloseScriptsM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
    Public Sub openhelp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "None"
        Editor.PAD.Enabled = False
        If openversiontg = False And openhelptg = False Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "ClayHelp.xml"), serr)
            SNDFORCE(helpfiles)
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - Help Information"
        ElseIf openhelptg = False And openversiontg = True And Me.Text = "Debugger - Help Information" Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False
            Editor.PAD.ReadOnly = False
            openversiontg = False
            Me.Text = "Debugger"
        ElseIf openhelptg = False And openversiontg = True Then
            Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : openversiontg = True
            Dim helpfiles As String = GetFileContents(Replace(DirHelpFiles, "Commands.xml", "ClayHelp.xml"), serr)
            SNDFORCE(helpfiles)
            Editor.PAD.Select(1, 0) : Editor.PAD.ScrollToCaret()
            Editor.PAD.ReadOnly = True
            Me.Text = "Debugger - Help Information"
        End If
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
        Editor.PAD.Enabled = True
    End Sub
    Private Sub OpenMisc(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenMiscM.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        ResumeMisc.Enabled = True
        Current = "Misc"
        Dim bob As New OpenFileDialog
        If MobileHealth = "/z[/YDebuged/z]" Then
            bob.InitialDirectory = "D:\Station\Programming\Releases\Resources"
        ElseIf MobileHealth = "/z[/GHealthy/z]" Then
            bob.InitialDirectory = CurDir() + "\Resources\"
        End If
        bob.Multiselect = False
        bob.Filter = "Terminal Groupings (*.xml)|*.xml|Text Files (*.txt)|*.txt"
        bob.Title = "Debugger - Open A Terminal Grouping"
        bob.ShowHelp = False
        bob.CheckFileExists = True
        bob.ShowDialog()
        DirMisc = bob.FileName
        MiscData = GetFileContents(DirMisc, serr)
        FormatTextColor(MiscData)
        SaveMiscM.Enabled = True
        CloseMiscM.Enabled = True
        updatestatus()
        If EditorOpen = False Then
            Editor.Show()
            EditorOpen = True
        End If
    End Sub
#End Region
#Region "Close Databases"
    Private Sub closeheader(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseHeaderM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : AtlasNodesData = ""
        SaveHeaderM.Enabled = False
        CloseHeaderM.Enabled = False
        updatestatus()
    End Sub
    Private Sub closemobile(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseMobileM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : MobData = ""
        SaveMobileM.Enabled = False
        CloseMobileM.Enabled = False
        updatestatus()
    End Sub
    Private Sub closeitem(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseItemM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : ItemData = ""
        SaveItemM.Enabled = False
        CloseItemM.Enabled = False
        updatestatus()
    End Sub
    Private Sub closeabilities(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseAbilitiesM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : AbilitiesData = ""
        SaveAbilitiesM.Enabled = False
        CloseAbilitiesM.Enabled = False
        updatestatus()
    End Sub
    Private Sub closeemote(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseEmoteM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : EmoteData = ""
        SaveEmoteM.Enabled = False
        CloseEmoteM.Enabled = False
        updatestatus()
    End Sub
    Private Sub closescripts(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseScriptsM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : ScriptData = ""
        SaveScriptsM.Enabled = False
        CloseScriptsM.Enabled = False
        updatestatus()
    End Sub
    Private Sub CloseCurrent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem1.Click
        If Current = "Misc" Then
            CloseMisc(0, e.Empty)
            Current = "None"
        ElseIf Current = "Items" Then
            closeitem(0, e.Empty)
            Current = "None"
        ElseIf Current = "Mobiles" Then
            closemobile(0, e.Empty)
            Current = "None"
        ElseIf Current = "AtlasNodes" Then
            closeheader(0, e.Empty)
            Current = "None"
        ElseIf Current = "Abilities" Then
            closeabilities(0, e.Empty)
            Current = "None"
        ElseIf Current = "Scripts" Then
            closescripts(0, e.Empty)
            Current = "None"
        ElseIf Current = "Emotes" Then
            closeemote(0, e.Empty)
            Current = "None"
        End If
        updatestatus()
    End Sub
    Private Sub CloseMisc(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseMiscM.Click
        Editor.PAD.Text = "" : Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000) : AddingDIGIT = False : AddingBracket = False : MiscData = ""
        SaveMiscM.Enabled = False
        CloseMiscM.Enabled = False
        ResumeMisc.Enabled = False
        updatestatus()
    End Sub
    Private Sub closeall(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        If ItemEditor.Visible = True Then ItemEditor.Close()
        If EmoteEditor.Visible = True Then EmoteEditor.Close()
        If MapEditor.Visible = True Then MapEditor.Close()
        If QuestEditor.Visible = True Then QuestEditor.Close()
        Me.Close()
    End Sub
#End Region
#Region "Save Databases"
    Private Sub savemobiles(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveMobileM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirMobs, serr)
        MobileChanged = False
    End Sub
    Private Sub saveitems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveItemM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirItems, serr)
        ItemChanged = False
    End Sub
    Private Sub saveabilities(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAbilitiesM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirAbilities, serr)
        AbilitiesChanged = False
    End Sub
    Private Sub saveemotes(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveEmoteM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirEmotes, serr)
        EmoteChanged = False
    End Sub
    Private Sub savescripts(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveScriptsM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirScripts, serr)
        ScriptChanged = False
    End Sub
    Private Sub saveheader(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveHeaderM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirAtlasNodes, serr)
        AtlasNodesChanged = False
    End Sub
    Private Sub SaveMisc(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveMiscM.Click
        bans = SaveTextToFile(Editor.PAD.Text, DirMisc, serr)
        MiscChanged = False
    End Sub
    Private Sub SaveCurrent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem1.Click
        If Current = "Misc" Then
            MiscSaved = True
            MiscChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirMisc, serr)
        ElseIf Current = "Items" Then
            ItemsSaved = True
            ItemChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirItems, serr)
        ElseIf Current = "Mobiles" Then
            MobilesSaved = True
            MobileChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirMobs, serr)
        ElseIf Current = "AtlasNodes" Then
            AtlasNodesSaved = True
            AtlasNodesChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirAtlasNodes, serr)
        ElseIf Current = "Abilities" Then
            AbilitiesSaved = True
            AbilitiesChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirAbilities, serr)
        ElseIf Current = "Scripts" Then
            ScriptsSaved = True
            ScriptChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirScripts, serr)
        ElseIf Current = "Emotes" Then
            EmotesSaved = True
            EmoteChanged = False
            FileChanged = False
            Editor.Text = "Debugger - Saved"
            bans = SaveTextToFile(Editor.PAD.Text, DirEmotes, serr)
        End If
        updatestatus()
    End Sub
    Private Sub CheckForSave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Dim Result As DialogResult
        Dim AreYouSure As MessageBox
        Dim SomethingChanged As Boolean = False
        Dim ChangeBox As String = ""
        If AtlasNodesChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "AtlasNodes"
        End If
        If ScriptChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "Scripts"
        End If
        If EmoteChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "Emotes"
        End If
        If MobileChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "Mobiles"
        End If
        If ItemChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "Items"
        End If
        If AbilitiesChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "Abilities"
        End If
        If MiscChanged = True Then
            SomethingChanged = True
            If ChangeBox <> "" Then ChangeBox += Chr(13)
            ChangeBox += "*.xml"
        End If
        If SomethingChanged = True Then
            Result = AreYouSure.Show("There were changes to some documents, save before exiting?" + Chr(13) + Chr(13) + ChangeBox, "Save before exiting?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)
            If Result = Windows.Forms.DialogResult.Yes Then
                If AtlasNodesChanged = True Then
                    saveheader(0, EventArgs.Empty)
                End If
                If ScriptChanged = True Then
                    savescripts(0, EventArgs.Empty)
                End If
                If EmoteChanged = True Then
                    saveemotes(0, EventArgs.Empty)
                End If
                If MobileChanged = True Then
                    savemobiles(0, EventArgs.Empty)
                End If
                If ItemChanged = True Then
                    saveitems(0, EventArgs.Empty)
                End If
                If AbilitiesChanged = True Then
                    saveabilities(0, EventArgs.Empty)
                End If
                If MiscChanged = True Then
                    SaveMisc(0, EventArgs.Empty)
                End If
            ElseIf Result = Windows.Forms.DialogResult.No Then
            ElseIf Result = Windows.Forms.DialogResult.Cancel Then
                e.Cancel = True
            End If
        End If
        Closing = True
        Application.Exit()
    End Sub
#End Region
#Region "Open Editors"
    Private Sub OpenScriptEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScriptEditorToolStripMenuItem.Click, ToolStripButton2.Click
        ScriptEditor.MdiParent = Me
        ScriptEditor.Show()
    End Sub
    Private Sub OpenMapEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MapEditorToolStripMenuItem.Click, ToolStripButton1.Click
        MapEditor.MdiParent = Me
        MapEditor.Show()
    End Sub
    Private Sub OpenMobEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MobEditorToolStripMenuItem.Click, ToolStripButton3.Click
        MobEditor.MdiParent = Me
        MobEditor.Show()
    End Sub
    Private Sub OpenItemEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemEditorToolStripMenuItem.Click, ToolStripButton4.Click
        ItemEditor.MdiParent = Me
        ItemEditor.Show()
    End Sub
    Private Sub OpenEmoteEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmoteEditorToolStripMenuItem.Click, ToolStripButton6.Click
        EmoteEditor.Show()
    End Sub
    Private Sub OpenQuestEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuestEditorToolStripMenuItem.Click, ToolStripButton5.Click
        QuestEditor.MdiParent = Me
        QuestEditor.Show()
    End Sub
    Private Sub OpenAbilityEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbilityEditorToolStripMenuItem.Click, ToolStripButton7.Click
        AbilityEditor.MdiParent = Me
        AbilityEditor.Show()
    End Sub
    Private Sub OpenHelpEditor(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpEditorToolStripMenuItem.Click, ToolStripButton9.Click
        HelpEditor.MdiParent = Me
        HelpEditor.Show()
    End Sub
#End Region
#Region "Button Clicks / Editors"
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        AbilityEditor.Show()
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        EmoteEditor.Show()
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        QuestEditor.Show()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ScriptEditor.Show()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ItemEditor.Show()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MobEditor.Show()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MapEditor.Show()
    End Sub
#End Region
#Region "Command Bar"
    Private Sub CheckSend(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles CMDbar.KeyPress
        If e.KeyChar = Chr(13) Then
            SNDBUG(">> " + CMDbar.Text + " <<")
            compilebug(CMDbar.Text)
            CMDbar.Text = ""
            e.Handled = True
        Else
            If DebuggerOpen = False Then
                DebuggerOpen = True
                CMDPanel.Show()
                CMDbar.Focus()
                CMDPanel.PAD.Text = ""
                SNDBUG("/CFor a list of commands, use the command: /whelp")
            End If
        End If
    End Sub
    Private Sub ClearText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDbar.Enter
        CMDbar.Text = ""
    End Sub
    Private Sub AddText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDbar.Leave
        CMDbar.Text = "<Command Input>"
    End Sub
    Private Sub compilebug(ByVal txt As String)
        Dim CaseSensitive As String = LTrim(RTrim(txt)), cmdvar As String = "", cmdlen As Short = 0, nputlen As Short = Len(txt) : CMDbar.Text = ""
        txt = LCase(LTrim(RTrim((txt))))
        For cmdlen = 1 To Len(txt) Step 1
            If Mid(txt, cmdlen, 1) = " " Then
                cmdvar = Mid(txt, 1, cmdlen - 1)
                cmdlen = Len(cmdvar)
                Exit For
            End If
        Next
        If txt = Mid("help", 1, nputlen) Or txt = Mid("commands", 1, nputlen) Or txt = Mid("cmds", 1, nputlen) Then
            SNDBUG("/WCurrent Commands/Z: /chelp, commands, cmds")
            SNDBUG("/Whelp color")
            SNDBUG("/Whelp syntax")
        ElseIf txt = Mid("help syntax", 1, nputlen) Then
            SNDBUG("/WSyntax is an important part of the debugger, however it can get in the way of important debugging processes. Because of this you can halt the syntax and resume it in the debugger commandline as needed.")
            SNDBUG("/C  syntax stop")
            SNDBUG("/C  syntax start")
        ElseIf txt = Mid("syntax start", 1, nputlen) Then
            If SyntaxStarted = True Then
                SNDBUG("/ySyntax already started..")
            Else
                SyntaxStarted = True
                SNDBUG("/YSyntax started!")
            End If
        ElseIf txt = Mid("syntax stop", 1, nputlen) Then
            If SyntaxStarted = True Then
                SyntaxStarted = False
                SNDBUG("/YSyntax stopped!")
            Else
                SNDBUG("/ySyntax already stopped..")
            End If
        ElseIf txt = Mid("help color", 1, nputlen) Then
            SNDBUG("/Wbgcolor %")
            SNDBUG("/Wtxtcolor %")
            SNDBUG("/W% = /zdark gray      /mdark magenta     /Rlight red")
            SNDBUG("/W    /Wlight gray     /Mlight magenta    /zblack")
            SNDBUG("/W    /Zwhite          /bdark blue")
            SNDBUG("/W    /ydark yellow    /Blight blue")
            SNDBUG("/W    /Ylight yellow   /cdark cyan")
            SNDBUG("/W    /gdark green     /Clight cyan")
            SNDBUG("/W    /Glight green    /rdark red")
        ElseIf cmdvar = Mid("bgcolor", 1, cmdlen) And nputlen > cmdlen + 1 Then
            Dim tmpa As String = LTrim(RTrim(Mid(txt, cmdlen + 1, Len(txt)))), tmplen As Short = Len(tmpa)
            If tmpa = Mid("dark gray", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkGray
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("black", 1, tmplen) Then
                Editor.PAD.BackColor = Color.Black
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light gray", 1, tmplen) Then
                Editor.PAD.BackColor = Color.LightGray
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("white", 1, tmplen) Then
                Editor.PAD.BackColor = Color.White
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark yellow", 1, tmplen) Then
                Editor.PAD.BackColor = Color.BurlyWood
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light yellow", 1, tmplen) Then
                Editor.PAD.BackColor = Color.Yellow
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark green", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkGreen
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light green", 1, tmplen) Then
                Editor.PAD.BackColor = Color.LightGreen
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark magenta", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkMagenta
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light magenta", 1, tmplen) Then
                Editor.PAD.BackColor = Color.LightPink
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark blue", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkBlue
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light blue", 1, tmplen) Then
                Editor.PAD.BackColor = Color.LightBlue
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark cyan", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkCyan
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light cyan", 1, tmplen) Then
                Editor.PAD.BackColor = Color.LightCyan
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("dark red", 1, tmplen) Then
                Editor.PAD.BackColor = Color.DarkRed
                SNDBUG("Background set!")
            ElseIf tmpa = Mid("light red", 1, tmplen) Then
                Editor.PAD.BackColor = Color.Red
                SNDBUG("Background set!")
            End If
        ElseIf cmdvar = Mid("txtcolor", 1, cmdlen) And nputlen > cmdlen + 1 Then
            Dim tmpa As String = LTrim(RTrim(Mid(txt, cmdlen + 1, Len(txt)))), tmplen As Short = Len(tmpa)
            If tmpa = Mid("dark gray", 1, tmplen) Then
                DefaultColor = "/z"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light gray", 1, tmplen) Then
                DefaultColor = "/W"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("white", 1, tmplen) Then
                DefaultColor = "/Z"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark yellow", 1, tmplen) Then
                DefaultColor = ""
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light yellow", 1, tmplen) Then
                DefaultColor = ""
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark green", 1, tmplen) Then
                DefaultColor = "/g"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light green", 1, tmplen) Then
                DefaultColor = "/G"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark magenta", 1, tmplen) Then
                DefaultColor = "/m"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light magenta", 1, tmplen) Then
                DefaultColor = "/M"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark blue", 1, tmplen) Then
                DefaultColor = "/b"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light blue", 1, tmplen) Then
                DefaultColor = "/B"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark cyan", 1, tmplen) Then
                DefaultColor = "/c"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light cyan", 1, tmplen) Then
                DefaultColor = "/C"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("dark red", 1, tmplen) Then
                DefaultColor = "/r"
                SNDBUG("Text default color set!")
            ElseIf tmpa = Mid("light red", 1, tmplen) Then
                DefaultColor = "/R"
                SNDBUG("Text default color set!")
            End If
        Else
            SNDBUG("/RCommand not recognized.")
        End If
    End Sub
#End Region
    Private Sub loaddebuggerstatus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Enabled = False
        Dim Debugged As Boolean = False
        'change background mdi client color
        Dim mdiClient1 As MdiClient = New System.Windows.Forms.MdiClient()
        mdiClient1.Dock = System.Windows.Forms.DockStyle.Fill
        mdiClient1.Name = "mdiClient1"
        mdiClient1.BackColor = Color.YellowGreen 'or whatever color you want...
        Me.Controls.AddRange(New System.Windows.Forms.Control() {mdiClient1})
        Me.IsMdiContainer = True
        SplashScreen.Show()
        While SplashScreen.Visible = True
            Application.DoEvents()
        End While
        If SplashScreen.Visible = False Then
            'ensure that resources folder is in the correct spot, and if not then allow user to locate it
            If My.Computer.FileSystem.DirectoryExists(CurDir() + "\Resources") Then
                ResourcesDir = CurDir() + "\Resources\"
            Else
                Debugged = True
                If My.Computer.FileSystem.FileExists(CurDir() + "\ResourceLocation.TG") Then 'this saves the location of the database for future reference if not found in correct spot
                    ResourcesDir = GetFileContents(CurDir() + "\ResourceLocation.TG")
                    If My.Computer.FileSystem.DirectoryExists(ResourcesDir) = False Then 'if the file is incorrect, or the resources has moved then
                        MessageBox.Show("The resources directory has moved, please re-locate the Version.xml file.", "Error: 332 - Directory Moved", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                        Dim FindResourcesFolder As New OpenFileDialog
                        FindResourcesFolder.InitialDirectory = CurDir()
                        FindResourcesFolder.Multiselect = False
                        FindResourcesFolder.Filter = "Terminal Groupings (*.xml)|*.xml|Text Files (*.txt)|*.txt"
                        FindResourcesFolder.Title = "Please Locate PLOS Resources File : Version.xml"
                        FindResourcesFolder.ShowHelp = False
                        FindResourcesFolder.CheckFileExists = True
                        FindResourcesFolder.ShowDialog()
                        ResourcesDir = Replace(FindResourcesFolder.FileName, "Version.xml", "")
                        My.Computer.FileSystem.DeleteFile(CurDir() + "\ResourceLocation.TG") 'delete the old location
                        SaveTextToFile(ResourcesDir, CurDir() + "\ResourceLocation.TG") 'save the new location
                    End If
                Else
                    Dim FindResourcesFolder As New OpenFileDialog
                    FindResourcesFolder.InitialDirectory = CurDir()
                    FindResourcesFolder.Multiselect = False
                    FindResourcesFolder.Filter = "Terminal Groupings (*.xml)|*.xml|Text Files (*.txt)|*.txt"
                    FindResourcesFolder.Title = "Please Locate PLOS Resources File : Version.xml"
                    FindResourcesFolder.ShowHelp = False
                    FindResourcesFolder.CheckFileExists = True
                    FindResourcesFolder.ShowDialog()
                    ResourcesDir = Replace(FindResourcesFolder.FileName, "Version.xml", "")
                    SaveTextToFile(ResourcesDir, CurDir() + "\ResourceLocation.TG")
                End If
            End If
            If ResourcesDir = "" Then
                MessageBox.Show("Closing application to avoid errors, resources folder not found", "Error 801 : Resources Missing", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Application.Exit()
            End If
            Me.Enabled = True
        End If
        'display the version of clay in the bottom of the program
        VersionStrip.Text = "Clay Version " + Diagnostics.FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileVersion
        'find the health of the major database files that could cause clay to crash if corrupt.
        'eventually it'd be nice to expand this to ascertain whether the files actually ARE corrupt.
        'at the moment it just displays corrupt if the files are missing. Needs to be expanded also
        'to ensure that the major editors won't open unless the files have a healthy status.
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\Mobiles\Mobs.xml") = False Then
            MobileHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                MobileHealth = "/z[/YDebuged/z]"
            Else
                MobileHealth = "/z[/GHealthy/z]"
            End If
            DirMobs = ResourcesDir + "\Databases\Mobiles\Mobs.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\World\RuinsOfVharmas.xml") = False Then
            MapHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                MapHealth = "/z[/YDebuged/z]"
            Else
                MapHealth = "/z[/GHealthy/z]"
            End If
            DirMaps = ResourcesDir + "\Databases\World\RuinsOfVharmas.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\World\AtlasNodes.xml") = False Then
            AtlasNodesHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                AtlasNodesHealth = "/z[/YDebuged/z]"
            Else
                AtlasNodesHealth = "/z[/GHealthy/z]"
            End If
            DirAtlasNodes = ResourcesDir + "\Databases\World\AtlasNodes.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\Items\Items.xml") = False Then
            ItemHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                ItemHealth = "/z[/YDebuged/z]"
            Else
                ItemHealth = "/z[/GHealthy/z]"
            End If
            DirItems = ResourcesDir + "\Databases\Items\Items.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\Emotes\Emotes.xml") = False Then
            EmoteHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                EmoteHealth = "/z[/YDebuged/z]"
            Else
                EmoteHealth = "/z[/GHealthy/z]"
            End If
            DirEmotes = ResourcesDir + "\Databases\Emotes\Emotes.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\Mobiles\Scripts.xml") = False Then
            ScriptHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                ScriptHealth = "/z[/YDebuged/z]"
            Else
                ScriptHealth = "/z[/GHealthy/z]"
            End If
            DirScripts = ResourcesDir + "\Databases\Mobiles\Scripts.xml"
        End If
        If My.Computer.FileSystem.FileExists(ResourcesDir + "\Databases\Abilities\Abilities.xml") = False Then
            AbilitiesHealth = "/z[/RCorrupt/z]"
        Else
            If Debugged = True Then
                AbilitiesHealth = "/z[/YDebuged/z]"
            Else
                AbilitiesHealth = "/z[/GHealthy/z]"
            End If
            DirAbilities = ResourcesDir + "\Databases\Abilities\Abilities.xml"
        End If
        DirHelpFiles = ResourcesDir + "\Databases\Help\Commands.xml"
        DirQuests = ResourcesDir + "\Databases\Quests\"
        If InStr(Command(), "\Mobs.xml") Then
            Current = "Mobiles"
            openmobiles("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf InStr(Command(), "\Items.xml") Then
            Current = "Items"
            openitems("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf InStr(Command(), "\AtlasNodes.xml") Then
            Current = "AtlasNodes"
            openheader("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf InStr(Command(), "\Scripts.xml") Then
            Current = "Scripts"
            openscripts("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf InStr(Command(), "\Emotes.xml") Then
            Current = "Emotes"
            openemotes("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf InStr(Command(), "\Abilities.xml") Then
            Current = "Abilities"
            openabilities("", EventArgs.Empty)
            Editor.PAD.Focus()
        ElseIf Command() <> "" Then
            Current = "Misc"
            DirMisc = Mid(Command(), 2, Len(Command()) - 2)
            If DirMisc <> "" Then
                MiscData = GetFileContents(DirMisc, serr)
            End If
            FormatTextColor(MiscData)
            SaveMiscM.Enabled = True
            CloseMiscM.Enabled = True
            Editor.PAD.Focus()
        End If
        updatestatus()
        'add forms to client (me)
        File_Browser.MdiParent = Me
        File_Browser.Show()
        DatabaseMonitor.MdiParent = Me
        CMDPanel.MdiParent = Me
        Editor.MdiParent = Me : EditorOpen = True
        Editor.PAD.SelectionStart = 0 : Editor.PAD.SelectionLength = 1 : Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
        Editor.Show()
    End Sub
    Private Sub ResumeMiscFile(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResumeMisc.Click
        If Current = "AtlasNodes" Then AtlasNodesData = Editor.PAD.Text
        If Current = "Mobiles" Then MobData = Editor.PAD.Text
        If Current = "Items" Then ItemData = Editor.PAD.Text
        If Current = "Emotes" Then EmoteData = Editor.PAD.Text
        If Current = "Misc" Then MiscData = Editor.PAD.Text
        If Current = "Abilities" Then AbilitiesData = Editor.PAD.Text
        If Current = "Scripts" Then ScriptData = Editor.PAD.Text
        Current = "Misc"
        FormatTextColor(MiscData)
        updatestatus()
    End Sub
    Private Sub ShortCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim keyascii As Integer = AscW(e.KeyChar)
        Dim isnumber As Boolean = Char.IsNumber(e.KeyChar)
        Dim isletter As Boolean = Char.IsLetter(e.KeyChar)
        If SyntaxStarted = True Then
            If AddingBracket = False Then
                e.KeyChar = CChar(UCase(ChrW(keyascii)))
            End If
            If isnumber = True Or isletter = True Then
                If Current = "AtlasNodes" Then
                    AtlasNodesChanged = True
                ElseIf Current = "Abilities" Then
                    AbilitiesChanged = True
                ElseIf Current = "Items" Then
                    ItemChanged = True
                ElseIf Current = "Emotes" Then
                    EmoteChanged = True
                ElseIf Current = "Scripts" Then
                    ScriptChanged = True
                ElseIf Current = "Misc" Then
                    MiscChanged = True
                ElseIf Current = "Mobiles" Then
                    MobileChanged = True
                End If
                updatestatus()
            End If
            If StartDigit = True Then
                AddingDIGIT = True
                StartDigit = False
            Else
                If AddingDIGIT = True Then
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                    If isletter = True Then
                        e.Handled = True
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub ShortcutCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Dim TestIt As Boolean = False
        If e.KeyCode = Keys.S And e.Control = True Then
            SaveCurrent(0, e.Empty)
        ElseIf e.KeyCode = Keys.X And e.Control = True Or e.KeyCode = Keys.Escape Then
            closeall(0, e.Empty)
        ElseIf e.KeyCode = Keys.M And e.Control = True Then
            OpenMapEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.O And e.Control = True Then
            OpenMobEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.I And e.Control = True Then
            OpenItemEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.E And e.Control = True Then
            OpenEmoteEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.Q And e.Control = True Then
            OpenQuestEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.L And e.Control = True Then
            CloseCurrent(0, e.Empty)
        ElseIf e.KeyCode = Keys.R And e.Control = True Then
            OpenScriptEditor(0, e.Empty)
        ElseIf e.KeyCode = Keys.B And e.Control = True Then
            OpenAbilityEditor(0, e.Empty)
        End If
        If SyntaxStarted = True Then
            If e.KeyCode = Keys.Enter Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
                AddingDIGIT = False
                AddingBracket = False
            ElseIf e.KeyCode = Keys.D3 And e.Shift = True And AddingBracket = False Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H333333)
                StartDigit = True
            ElseIf e.KeyCode = Keys.D9 And e.Shift = True And AddingBracket = False And AddingDIGIT = True Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                AddingBracket = True
                AddingDIGIT = False
            ElseIf e.KeyCode = Keys.D0 And e.Shift = True And AddingBracket = True And AddingDIGIT = False Then
                Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
            ElseIf AddingBracket = True Then
                Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
            End If
        End If
    End Sub
    Private Sub GetFormatLocation(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If SyntaxStarted = True Then
            Dim tmp0 As Integer = Editor.PAD.SelectionStart, tmp1 As Integer = Editor.PAD.SelectionStart, Found As Boolean = False
            Dim TheLine As String
            If tmp0 > 1 Then
                For tmp0 = Editor.PAD.SelectionStart To 1 Step -1
                    If Mid(Editor.PAD.Text, tmp0, 1) = Chr(10) Then
                        TheLine = Mid(Editor.PAD.Text, tmp0 + 1, tmp1 - tmp0)
                        Found = True
                        Exit For
                    End If
                Next
            End If
            If Found = False Then TheLine = Mid(Editor.PAD.Text, 1, tmp1)
            AddingDIGIT = False
            AddingBracket = False
            Editor.PAD.SelectionColor = Color.FromArgb(&H660000)
            Dim StepNum As Short = 0
            For tmp0 = 1 To Len(TheLine) Step 1
                If Mid(TheLine, tmp0, 1) = "#" And StepNum = 0 Then
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF0000)
                    AddingDIGIT = True
                    AddingBracket = False
                    StepNum = 1
                ElseIf Mid(TheLine, tmp0, 1) = "(" And StepNum = 1 Then
                    AddingBracket = True
                    AddingDIGIT = False
                    Editor.PAD.SelectionColor = Color.FromArgb(&H6666)
                    StepNum = 2
                ElseIf Mid(TheLine, tmp0, 1) = ")" And StepNum = 2 Then
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFFFFFF)
                    AddingBracket = True
                    AddingDIGIT = False
                    StepNum = 3
                ElseIf Mid(TheLine, tmp0, 2) = "//" Then
                    Editor.PAD.SelectionColor = Color.FromArgb(&HFF00)
                    AddingBracket = False
                    AddingDIGIT = False
                    Exit For
                End If
            Next
        End If
    End Sub
    Private Sub ReCut(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If SyntaxStarted = True Then
            If e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Or e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Then
                GetFormatLocation(0, EventArgs.Empty)
            ElseIf e.KeyCode = Keys.Back Or e.KeyCode = Keys.Delete Then
                FormatLineColor()
            ElseIf e.KeyCode = Keys.X And e.Control = True Then
                FormatLineColor()
            ElseIf e.KeyCode = Keys.V And e.Control = True Then
                FormatTextColor(Editor.PAD.Text)
            ElseIf e.KeyCode = Keys.D3 And e.Shift = True Then
                FormatLineColor()
            ElseIf e.KeyCode = Keys.D9 And e.Shift = True Then
                FormatLineColor()
            ElseIf e.KeyCode = Keys.D0 And e.Shift = True Then
                FormatLineColor()
            ElseIf e.KeyCode = 191 Then
                FormatLineColor()
            End If
        End If
    End Sub
    Public Sub updatestatus()
        DatabaseMonitor.FILEStatus.Text = ""
        Dim tmpstr As String = ""
        Dim tmp1 As Integer = 0
        If Current = "Misc" Then
            For tmp1 = Len(DirMisc) To 1 Step -1
                If Mid(DirMisc, tmp1, 1) = "\" Then
                    Exit For
                Else
                    tmpstr = Mid(DirMisc, tmp1, 1) + tmpstr
                End If
            Next
            Me.Text = "Debugger - " + tmpstr
        ElseIf Current = "Items" Then
            Me.Text = "Debugger - Items.xml"
        ElseIf Current = "Mobiles" Then
            Me.Text = "Debugger - Mobs.xml"
        ElseIf Current = "AtlasNodes" Then
            Me.Text = "Debugger - AtlasNodes.xml"
        ElseIf Current = "Abilities" Then
            Me.Text = "Debugger - Abilities.xml"
        ElseIf Current = "Scripts" Then
            Me.Text = "Debugger - Scripts.xml"
        ElseIf Current = "Emotes" Then
            Me.Text = "Debugger - Emotes.xml"
        Else
            Me.Text = "Debugger"
        End If
        DatabaseMonitor.FILEStatus.Text = ""
        SND("/wAtlasNodes.xml/Z: /CDebugger " + AtlasNodesHealth)
        SND("/wMobiles.xml   /Z: /CDebugger " + MobileHealth)
        SND("/wItems.xml     /Z: /CDebugger " + ItemHealth)
        SND("/wEmotes.xml    /Z: /CDebugger " + EmoteHealth)
        SND("/wScripts.xml   /Z: /CDebugger " + ScriptHealth)
        SND("/wAbilities.xml /Z: /CDebugger " + AbilitiesHealth)
        If MiscSaved = False Then
            If MiscData = "" Then
                SND("/w*.xml         /Z: /rClosed   /z[/zEmpty/z]")
            Else
                If Current = "Misc" Then
                    If MiscChanged = True Then
                        SND("/w*.xml         /Z: /yChanged  /z[/GHealthy/z]")
                    Else
                        SND("/w*.xml         /Z: /GOpen     /z[/GHealthy/z]")
                    End If
                Else
                    SND("/w*.xml         /Z: /gOpen     /z[/GHealthy/z]")
                End If
            End If
        Else
            SND("/w*.xml         /Z: /YSaved!   /z[/GHealthy/z]")
            MiscSaved = False
        End If
        Editor.PAD.ReadOnly = False
    End Sub
    Private Sub ToggleDatabaseStatus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        If FileStatusOpen = False Then
            DatabaseMonitor.Show()
            FileStatusOpen = True
        Else
            DatabaseMonitor.Hide()
            FileStatusOpen = False
        End If
    End Sub
    Private Sub Wordwrapchange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Editor.PAD.WordWrap = True
        Else
            Editor.PAD.WordWrap = False
        End If
    End Sub
End Class